package com.pine.manager.pineframework;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.pine.dao.pineframework.entity.SysMenu;
import com.pine.dao.pineframework.mapper.SysMenuMapper;
import com.pine.manager.core.BaseManager;
import com.pine.manager.pineframework.bo.SysMenuBo;
import com.pine.manager.pineframework.convertors.SysMenuConvertor;
import com.pine.manager.pineframework.query.SysMenuQuery;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 菜单表 管理类
 * </p>
 *
 * @author pine manage
 * @since 2024-08-12
 */
@Component
public class SysMenuManager extends BaseManager<SysMenuMapper, SysMenu, Long, SysMenuBo, SysMenuQuery, SysMenuConvertor> {

    @Resource
    private SysMenuConvertor sysMenuConvertor;

    @Override
    public LambdaQueryWrapper<SysMenu> encapsulateQueryWrapper(SysMenuQuery query) {
        LambdaQueryWrapper<SysMenu> queryWrapper = super.encapsulateQueryWrapper(query);
        if (query == null) {
            return queryWrapper;
        }

        // 组装查询条件
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getParentId()), SysMenu::getParentId, query.getParentId());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getName()), SysMenu::getName, query.getName());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getMenuType()), SysMenu::getMenuType, query.getMenuType());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRouteName()), SysMenu::getRouteName, query.getRouteName());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRoutePath()), SysMenu::getRoutePath, query.getRoutePath());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRouteParams()), SysMenu::getRouteParams, query.getRouteParams());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getComponent()), SysMenu::getComponent, query.getComponent());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getPermission()), SysMenu::getPermission, query.getPermission());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getVisible()), SysMenu::getVisible, query.getVisible());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getSort()), SysMenu::getSort, query.getSort());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getIcon()), SysMenu::getIcon, query.getIcon());
        queryWrapper.eq(ObjectUtils.isNotEmpty(query.getRedirect()), SysMenu::getRedirect, query.getRedirect());
        queryWrapper.ge(ObjectUtils.isNotEmpty(query.getUpdateTimeStart()), SysMenu::getUpdateTime, query.getUpdateTimeStart());
        queryWrapper.le(ObjectUtils.isNotEmpty(query.getUpdateTimeEnd()), SysMenu::getUpdateTime, query.getUpdateTimeEnd());

        // 排序
        queryWrapper.orderByAsc(SysMenu::getSort);
        return queryWrapper;
    }
}
